package utils

import (
    //"errors"
    //"net"
    //"fmt"
    //"log"
    "fmt"
    "github.com/go-ping/ping"
)

//子网掩码转字符串
func IPv4ToString(m []byte) string {
    if len(m) != 4 {
        panic("ipv4Mask: len must be 4 bytes")
    }
    return fmt.Sprintf("%d.%d.%d.%d", m[0], m[1], m[2], m[3])
}

/*网络 ping */
func  Ping(raddr string) (*ping.Statistics, error) {
    pinger, err := ping.NewPinger(raddr)
    if err != nil {
        return &ping.Statistics{} ,err
    }
    pinger.Count = 3
    pinger.SetPrivileged(true)
    err = pinger.Run() // Blocks until finished.
    if err != nil {
        return &ping.Statistics{},err
    }
    return pinger.Statistics(),nil // get send/receive/duplicate/rtt stats
}
